package com.itheima.mapper.sms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.vo.dto.SmsFlashPromotionProductRelationDto;
import com.itheima.vo.pojo.SmsFlashPromotionProductRelation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SmsFlashPromotionProductRelationMapper extends BaseMapper<SmsFlashPromotionProductRelation> {

    @Select("SELECT COUNT(*) FROM sms_flash_promotion_product_relation s \n" +
            "            LEFT JOIN pms_product p ON s.`product_id`=p.`id`\n" +
            "            WHERE s.`flash_promotion_id` = #{flashPromotionId}\n" +
            "            AND s.`flash_promotion_session_id`=#{flashPromotionSessionId}")
    long count(@Param("flashPromotionId") Long flashPromotionId, @Param("flashPromotionSessionId") Long flashPromotionSessionId);


    //分页查询相关商品及限时购促销信息
    @Select("SELECT\n" +
            "            r.id,\n" +
            "            r.flash_promotion_price,\n" +
            "            r.flash_promotion_count,\n" +
            "            r.flash_promotion_limit,\n" +
            "            r.flash_promotion_id,\n" +
            "            r.flash_promotion_session_id,\n" +
            "            r.product_id,\n" +
            "            r.sort,\n" +
            "            p.id p_id,\n" +
            "            p.`name` p_name,\n" +
            "            p.product_sn p_product_sn,\n" +
            "            p.price p_price,\n" +
            "            p.stock p_stock\n" +
            "        FROM\n" +
            "            sms_flash_promotion_product_relation r\n" +
            "            LEFT JOIN pms_product p ON r.product_id = p.id\n" +
            "        WHERE\n" +
            "            r.flash_promotion_id = #{flashPromotionId}\n" +
            "            AND r.flash_promotion_session_id = #{flashPromotionSessionId}\n" +
            "        ORDER BY r.sort DESC")
    List<SmsFlashPromotionProductRelation> listAll(@Param("flashPromotionId") Long flashPromotionId, @Param("flashPromotionSessionId") Long flashPromotionSessionId);
}
